package Task19;

import java.util.Scanner;

public class Main2 {
    public static String getManlen(String str1,String str2){
        int len1 = str1.length();
        int len2 = str2.length();
        char[] arr1 = str1.toCharArray();
        char[] arr2 = str2.toCharArray();
        //设定一个最长子串长度
        int maxlen = 0;
        //最长子串起始位置
        int start = 0;
        int[][] array = new int[len1+1][len2+1];
        for(int i = 1 ; i <= len1; i++ ){
            for(int j = 1;j <= len2;j++){
                if(arr1[i - 1] == arr2[ j - 1]){
                    array[i][j] = array[i - 1][j - 1] + 1;
                    if(maxlen < array[i][j]){
                        maxlen = array[i][j];
                        start = i - maxlen;
                    }
                }
            }
        }
        return str1.substring(start,start + maxlen);
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String str1 = in.nextLine();
            String str2 = in.nextLine();
            if(str1.length() < str2.length()){
                System.out.println(getManlen(str1,str2));
            }else{
                System.out.println(getManlen(str2,str1));
            }
        }
    }
}
